package com.ewancle.controller

import io.micronaut.http.MediaType
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Get
import io.micronaut.http.annotation.PathVariable
import io.micronaut.http.annotation.QueryValue
import reactor.core.publisher.Mono


@Controller("/hello") // (1)
class HelloController {

    @Get(produces = [MediaType.TEXT_PLAIN], value = "/test") // (2)
    fun index(): String {
        return "Hello World" // (3)
    }

    // http://localhost:8080/hello/Lucas?lang=en
    @Get("/{name}", produces = [MediaType.TEXT_PLAIN])
    fun sayHello(@PathVariable name: String, @QueryValue(defaultValue = "en") lang: String): String {
        return if (lang == "en") {
            "Hello, $name!"
        } else {
            "你好，$name!"
        }
    }

    @Get("/reactor/{name}")
    fun greet(name: String): Mono<String> {
        return Mono.just("响应式")
    }
}